home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / fileli1a / frmlistf.frm < prev    next >
Text File  |  1999-10-08  |  10KB  |  413 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "File List tool"
  4.    ClientHeight    =   3270
  5.    ClientLeft      =   60
  6.    ClientTop       =   630
  7.    ClientWidth     =   6750
  8.    LinkTopic       =   "Form1"
  9.    MaxButton       =   0   'False
  10.    ScaleHeight     =   3270
  11.    ScaleWidth      =   6750
  12.    StartUpPosition =   2  'CenterScreen
  13.    Begin VB.TextBox Text1 
  14.       Height          =   285
  15.       Left            =   0
  16.       TabIndex        =   1
  17.       Top             =   2640
  18.       Width           =   6735
  19.    End
  20.    Begin VB.ListBox List1 
  21.       Height          =   2595
  22.       ItemData        =   "FrmListFiles.frx":0000
  23.       Left            =   0
  24.       List            =   "FrmListFiles.frx":0002
  25.       MultiSelect     =   2  'Extended
  26.       OLEDropMode     =   1  'Manual
  27.       TabIndex        =   0
  28.       TabStop         =   0   'False
  29.       Top             =   0
  30.       Width           =   6735
  31.    End
  32.    Begin VB.Label Label1 
  33.       Caption         =   "Total Files"
  34.       Height          =   255
  35.       Left            =   0
  36.       TabIndex        =   2
  37.       Top             =   3000
  38.       Width           =   6735
  39.    End
  40.    Begin VB.Menu File 
  41.       Caption         =   "&File"
  42.       Begin VB.Menu NewList 
  43.          Caption         =   "&New"
  44.          Shortcut        =   ^N
  45.       End
  46.       Begin VB.Menu OpenList 
  47.          Caption         =   "&Open"
  48.          Shortcut        =   ^O
  49.       End
  50.       Begin VB.Menu Reopen 
  51.          Caption         =   "ReOpen"
  52.          Begin VB.Menu Clear 
  53.             Caption         =   "Clear List"
  54.          End
  55.          Begin VB.Menu mnuSepMRU 
  56.             Caption         =   "-"
  57.          End
  58.          Begin VB.Menu mnuReopenSub 
  59.             Caption         =   "None"
  60.             Enabled         =   0   'False
  61.             Index           =   0
  62.          End
  63.       End
  64.       Begin VB.Menu Save 
  65.          Caption         =   "&Save"
  66.          Shortcut        =   ^S
  67.       End
  68.       Begin VB.Menu mnuSep 
  69.          Caption         =   "-"
  70.       End
  71.       Begin VB.Menu Exit 
  72.          Caption         =   "E&xit"
  73.          Shortcut        =   ^Q
  74.       End
  75.    End
  76.    Begin VB.Menu Help 
  77.       Caption         =   "&Help"
  78.       Begin VB.Menu LstFiles 
  79.          Caption         =   "&With List Files"
  80.       End
  81.       Begin VB.Menu About 
  82.          Caption         =   "&About"
  83.       End
  84.    End
  85. End
  86. Attribute VB_Name = "Form1"
  87. Attribute VB_GlobalNameSpace = False
  88. Attribute VB_Creatable = False
  89. Attribute VB_PredeclaredId = True
  90. Attribute VB_Exposed = False
  91. Dim Dirty As Boolean, MRUNum As Integer
  92.  
  93. Private Sub AddToMRUX(FileNam As String)
  94.  
  95. Dim X As Integer
  96.  
  97. ' x = 1 MRU Number
  98. For X = 1 To MRUNum
  99.     ' Checks for duplicates
  100.     If FileNam = MRUX(X) Then Exit Sub
  101. Next
  102.  
  103. ' Opens MRU data file
  104. Open App.Path + "\MRU.dat" For Output As #1
  105.     ' Puts new file name if it exists
  106.     If FileExists(FileNam) Then Print #1, FileNam
  107.     For X = 1 To MRUNum
  108.         ' Puts other filenames if they exist
  109.         If X <> 15 Then If FileExists(MRUX(X)) Then Print #1, MRUX(X)
  110.     Next
  111. Close
  112.  
  113. ' Keeps track of number of MRU
  114. If MRUNum <> 15 Then MRUNum = MRUNum + 1
  115.  
  116. ' Clears displayed MRU list
  117. mnuReopenSub(0).Caption = "None"
  118. mnuReopenSub(0).Enabled = False
  119.  
  120. For Num = 1 To mnuReopenSub.Count - 1
  121.     mnuReopenSub(Num).Visible = False
  122. Next
  123.  
  124. ' Displays New MRU List
  125. DisplayMRU
  126.  
  127. End Sub
  128.  
  129. Private Sub CreateReopenItem(ByVal menu_caption As String)
  130.  
  131. Static Menuro_Num As Integer
  132.  
  133. ' Checks first MRU line to see if it's got anything (is enabled if it has anything
  134. If mnuReopenSub(0).Enabled Then
  135.     ' Tracking counter
  136.     Menuro_Num = Menuro_Num + 1
  137.     ' Loads new menu item
  138.     Load mnuReopenSub(Menuro_Num)
  139. Else
  140.     ' Enables First
  141.     mnuReopenSub(0).Enabled = True
  142.     ' Resets counter
  143.     Menuro_Num = 0
  144. End If
  145.  
  146. ' Puts MRU caption
  147. mnuReopenSub(Menuro_Num).Caption = menu_caption
  148.  
  149. ' Tracker
  150. Num = Menuro_Num
  151.  
  152. End Sub
  153.  
  154. Private Sub DisplayMRU()
  155.  
  156. Dim X As Integer
  157.  
  158. ' Opens MRU datafile
  159. Open App.Path + "\MRU.dat" For Input As #1
  160.     X = 1
  161.     Do While Not EOF(1)
  162.         ' Inputs MRU data
  163.         Line Input #1, MRUX(X)
  164.         ' Tracking counter
  165.         X = X + 1
  166.     Loop
  167. Close
  168.  
  169. ' Tracks MRU Number
  170. MRUNum = X - 1
  171.  
  172. For X = 1 To MRUNum
  173.     ' If file exists, put menu item
  174.     If FileExists(MRUX(X)) Then CreateReopenItem (ExtractFileName(MRUX(X)))
  175. Next
  176.  
  177. End Sub
  178.  
  179. Private Sub OpenMyList(FileNam As String)
  180.  
  181. Dim Tot As String
  182.  
  183. ' Checks to see if file exists
  184. If FileExists(FileNam) Then
  185.     ' Clears list
  186.     List1.Clear
  187.     ' Gets file number
  188.     FF = FreeFile
  189.     ' Opens file
  190.     Open FileNam For Input As #FF
  191.         Do While Not EOF(FF)
  192.             ' Gets data
  193.             Line Input #FF, Lne
  194.             ' Adds data to list
  195.             List1.AddItem Lne
  196.         Loop
  197.     Close
  198.     
  199.     ' Gets total number of files
  200.     Tot = List1.ListCount
  201.     
  202.     ' Displays total
  203.     Label1.Caption = Tot + " Total Files"
  204.     ' Adds file to MRU list
  205.     AddToMRUX (FileNam)
  206. Else
  207.     ' If file doesn't exist, display warning
  208.     MsgBox "That file does not exist", vbExclamation, "File Not Found!"
  209. End If
  210.  
  211. End Sub
  212.  
  213. Private Sub About_Click()
  214.  
  215. ' About this program
  216. MsgBox "If you find this program or source code useful, drop me a line at (phillip@softhome.net" & vbNewLine & _
  217.         "If you use this code, please site me in the credits.  Also tell me if you have any" & vbNewLine & _
  218.         "suggestions or bug (fixes).", vbInformation, "About this Program"
  219.  
  220. End Sub
  221.  
  222. Private Sub Clear_Click()
  223.  
  224. Dim None As String
  225.  
  226. ' Resets first MRU entry
  227. mnuReopenSub(0).Caption = "None"
  228. mnuReopenSub(0).Enabled = False
  229.  
  230. ' Resets other MRU entries
  231. For Num = 1 To mnuReopenSub.Count - 1
  232.     mnuReopenSub(Num).Visible = False
  233. Next
  234.  
  235. None = ""
  236.  
  237. ' Writes blank MRU datafile
  238. Open App.Path + "\MRU.dat" For Output As #1
  239. Close
  240.  
  241. ' Resets MRU tracking number
  242. MRUNum = 0
  243.  
  244. End Sub
  245.  
  246. Private Sub Exit_Click()
  247.  
  248. ' Unloads form
  249. Unload Me
  250.  
  251. End Sub
  252.  
  253. Private Sub Form_Load()
  254.  
  255. 'Displays MRU
  256. DisplayMRU
  257.  
  258. End Sub
  259.  
  260. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  261.  
  262. Dim Response As String
  263.  
  264. ' If list has changed it is dirty
  265. If Dirty Then
  266.     ' Prompts to save "dirty" list
  267.     Response = MsgBox("Do you want to save this list", vbYesNoCancel, "List has changed!")
  268.     ' Responds to user input
  269.     Select Case Response
  270.         Case vbYes
  271.             'Save the list
  272.             Save_Click
  273.         Case vbNo
  274.             ' Don't save list
  275.             Cancel = False
  276.         Case vbCancel
  277.             ' Cancels quit
  278.             Cancel = True
  279.     End Select
  280. End If
  281.  
  282. End Sub
  283.  
  284. Private Sub List1_DblClick()
  285.  
  286. ' Removes list item
  287. List1.RemoveItem (List1.ListIndex)
  288.  
  289. ' List has changed, it is "Dirty"
  290. Dirty = True
  291.  
  292. End Sub
  293.  
  294. Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  295.  
  296. Dim fname As Variant, lFileSize As String
  297.  
  298. For Each fname In Data.Files
  299.     ' Adds formatted filename and file size to list
  300.     List1.AddItem ExtractFileName(fname + ": " + FormatFileSize(FileLen(fname)))
  301. Next
  302.  
  303. ' Indicate we did nothing with the files.
  304. Effect = vbDropEffectNone
  305.  
  306. ' List has changed, it is "Dirty"
  307. Dirty = True
  308.  
  309. End Sub
  310.  
  311. Private Sub LstFiles_Click()
  312.  
  313. ' Help with this program
  314. MsgBox "This program lets you create lists of files by droping the files" & vbNewLine & _
  315.         "onto the listbox.  You can search the list by typing into the" & vbNewLine & _
  316.         "textbox, the matching files will be selected in the textbox." & vbNewLine & vbNewLine & _
  317.         "Remove list items by double clicking on them." & vbNewLine & vbNewLine & _
  318.         "You can open previously made lists with the MRU provided on the" & vbNewLine & _
  319.         "File>ReOpen> Menu.  To Clear the MRU Press Clear List.", vbInformation, "Help with listfiles"
  320.         
  321. End Sub
  322.  
  323. Private Sub mnuReopenSub_Click(Index As Integer)
  324.  
  325. ' Opens MRU Selected
  326. OpenMyList (MRUX(Index + 1))
  327.  
  328. End Sub
  329.  
  330. Private Sub NewList_Click()
  331.  
  332. ' Clears li